﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;

namespace DAO
{
    public class QuayDAO
    {
        ConnectDB conn = new ConnectDB();
        string str;
        //Load dữ liệu
        public DataTable LoadQuay()
        {
            return conn.LayDuLieu("select *from Quay");
        }
        //lay MaKho
        public DataTable Kho()
        {
            return conn.LayDuLieu("select MaKho from Kho");
        }
        // insert va update
        public void IsUp_Quay(QuayDTO  p, bool flag)
        {
            string MaQuay = p.MaQuay;
            string MaKho = p.MaKho;
            string TenQuay = p.TenQuay;
            float SoLuongTrenQuay = p.SoLuongTrenQuay ;
            float SoLuongQuyDinh = p.SoLuongQuyDinh ;
            if (flag == true)
            {
                //(Ma Kho, Ten Quay, SoLuongTrenQuay, SoLuongQuyDinh)
                str = "INSERT Quay ( MaKho, TenQuay, SoLuongTrenQuay, SOLuongQuyDinh) VALUES('"+ MaKho  +"',N'" + TenQuay + "'," + SoLuongTrenQuay  + "," + SoLuongQuyDinh  + ")";
            }
            else
            {
                str = "UPDATE Quay SET MaKho = '" + MaKho + "', TenQuay =  N'" + TenQuay + "', SoLuongTrenQuay =  '" + SoLuongTrenQuay + "', SoLuongQuyDinh =  '" + SoLuongQuyDinh + "'";
            }
            conn.excute(str);

        }
        //delete
        public void Del_Quay(QuayDTO p)
        {
            string MaQuay = p.MaQuay;
            str = "DELETE Quay WHERE MaQuay='" + MaQuay + "'";
            conn.excute(str);
        }
        //Tim kiem
        public DataTable TimQuay(QuayDTO p, bool flag)
        {
            string MaQuay = p.MaQuay;
            string TenQuay = p.TenQuay;
            if (flag == true)
            {
                str = "select * from Quay where MaQuay like'%" + MaQuay + "%'";
            }
            else
            {
                str = "select * from Quay where TenQuay like'%" + TenQuay + "%'";
            }
            return conn.LayDuLieu(str);

        }
    }
}
